Python 3.8 by Dunn Nat
Author: Dunn, Nat [Dunn, Nat] , Date: April 3, 2020
, Views: 453
Challenge Solution: file-processing/Solutions/word_search_challenge.py
def search(word, text): """Return tuple holding line num and line text.""" results = [] for line in enumerate(text, 1): if line[1].find(word) >= 0: results.append(line) return results def main(): with open('my_files/zen_of_python.txt') as f: zop = f.readlines() word = input('Enter search word: ') results = search(word, zop) if not results: print(word, 'was not found.') for result in results: print(word, ' appears on line ', result[0], ': ', result[1], sep='', end='') main()
Download
Copyright Disclaimer:
This site does not store any files on its server. We only index and link
to content provided by other sites. Please contact the content providers
to delete copyright contents if any and email us, we'll remove relevant
links or contents immediately.